Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added FormData support #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

liamcurry
Copy link

This PR adds basic FormData support using the form-data module (same module that request uses). This may not cover all cases, but it's working in my project so I thought I'd share.

Here's an example of how you'd use this to polyfill FormData in Node:

import XMLHttpRequest from 'xhr2';
global.XMLHttpRequest = XMLHttpRequest;
global.FormData = XMLHttpRequest.FormData;

@pwnall
Copy link
Owner

pwnall commented May 1, 2017

Sorry for the late response. This is a feature I'd be interested in, and I like that you followed the choices in request. Can you please add tests?

@mebibou
Copy link

mebibou commented Oct 30, 2018

This doesn't work in this case:

const data = new FormData();
data.append('a', 1);
data.append('b', 1);

In this case, it adds some function in the streams of the FormData forcing the data.on('data') to be completely called asynchronously. In other words, you have to liste to data.on('end') callback function to be sure to have the complete body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants